package hclfns

import (
	"github.com/ihaiker/tfwrapper/internal/errors"
	"os"
)

// Return the repository root as an absolute path
func getEnv(opts *FunctionOptions, args []string) (string, error) {
	if len(args) == 0 {
		return "", errors.New("get_env: missing environment variable name")
	}
	envName := args[0]
	if os.Getenv(envName) != "" {
		return os.Getenv(envName), nil
	}
	if len(args) == 1 {
		return "", errors.New("get_env: environment variable not set")
	}
	return args[1], nil
}
